package com.ls.socketio.service.impl;

import com.ls.socketio.bean.BaseCommand;
import com.ls.socketio.config.Properties;
import com.ls.socketio.service.SendService;
import com.ls.socketio.view.InfoView;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author liShan
 * @date 2019/9/4 23:23
 */
@Service
public class SendServiceImpl implements SendService {

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private Properties properties;

    @Override
    public <E extends BaseCommand> InfoView execute(E command, Class<E> eClass) {
        return restTemplate.postForObject(
                properties.getSendUrlMap().get(eClass.getName()), command, InfoView.class);
    }
}
